Ensure that all fields of evtchn_op_t are initialised when
authorkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Thu, 6 Oct 2005 09:42:32 +0000 (10:42 +0100)
committerkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Thu, 6 Oct 2005 09:42:32 +0000 (10:42 +0100)
making an event_channel_op hypercall. Stefan Berger gets the
credit for diagnosing nasty domU driver problems that were a
result of garbage fields.

Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
Signed-off-by: Keir Fraser <keir@xensource.com>
linux-2.6-xen-sparse/arch/xen/kernel/evtchn.c
linux-2.6-xen-sparse/drivers/xen/blkback/interface.c
linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c
linux-2.6-xen-sparse/drivers/xen/blktap/interface.c
linux-2.6-xen-sparse/drivers/xen/netback/interface.c
linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c
linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c
linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c
linux-2.6-xen-sparse/include/asm-xen/evtchn.h
tools/libxc/xc_evtchn.c

index 647f1f240b141428baa6c2433de33dbb8c3a612c..c9555d5e70f9f4062432aa52ea6097317484d108 100644 (file)
@@ -180,14 +180,13 @@ static int find_unbound_irq(void)
 
 int bind_virq_to_irq(int virq)
 {
-       evtchn_op_t op;
+       evtchn_op_t op = { .cmd = EVTCHNOP_bind_virq };
        int evtchn, irq;
        int cpu = smp_processor_id();
 
        spin_lock(&irq_mapping_update_lock);
 
        if ((irq = per_cpu(virq_to_irq, cpu)[virq]) == -1) {
-               op.cmd              = EVTCHNOP_bind_virq;
                op.u.bind_virq.virq = virq;
                op.u.bind_virq.vcpu = cpu;
                BUG_ON(HYPERVISOR_event_channel_op(&op) != 0);
@@ -212,7 +211,7 @@ EXPORT_SYMBOL(bind_virq_to_irq);
 
 void unbind_virq_from_irq(int virq)
 {
-       evtchn_op_t op;
+       evtchn_op_t op = { .cmd = EVTCHNOP_close };
        int cpu    = smp_processor_id();
        int irq    = per_cpu(virq_to_irq, cpu)[virq];
        int evtchn = irq_to_evtchn[irq];
@@ -220,7 +219,6 @@ void unbind_virq_from_irq(int virq)
        spin_lock(&irq_mapping_update_lock);
 
        if (--irq_bindcount[irq] == 0) {
-               op.cmd          = EVTCHNOP_close;
                op.u.close.dom  = DOMID_SELF;
                op.u.close.port = evtchn;
                BUG_ON(HYPERVISOR_event_channel_op(&op) != 0);
@@ -245,14 +243,13 @@ EXPORT_SYMBOL(unbind_virq_from_irq);
 
 int bind_ipi_to_irq(int ipi)
 {
-       evtchn_op_t op;
+       evtchn_op_t op = { .cmd = EVTCHNOP_bind_ipi };
        int evtchn, irq;
        int cpu = smp_processor_id();
 
        spin_lock(&irq_mapping_update_lock);
 
        if ((evtchn = per_cpu(ipi_to_evtchn, cpu)[ipi]) == -1) {
-               op.cmd = EVTCHNOP_bind_ipi;
                op.u.bind_ipi.vcpu = cpu;
                BUG_ON(HYPERVISOR_event_channel_op(&op) != 0);
                evtchn = op.u.bind_ipi.port;
@@ -278,7 +275,7 @@ EXPORT_SYMBOL(bind_ipi_to_irq);
 
 void unbind_ipi_from_irq(int ipi)
 {
-       evtchn_op_t op;
+       evtchn_op_t op = { .cmd = EVTCHNOP_close };
        int cpu    = smp_processor_id();
        int evtchn = per_cpu(ipi_to_evtchn, cpu)[ipi];
        int irq    = evtchn_to_irq[evtchn];
@@ -286,7 +283,6 @@ void unbind_ipi_from_irq(int ipi)
        spin_lock(&irq_mapping_update_lock);
 
        if (--irq_bindcount[irq] == 0) {
-               op.cmd          = EVTCHNOP_close;
                op.u.close.dom  = DOMID_SELF;
                op.u.close.port = evtchn;
                BUG_ON(HYPERVISOR_event_channel_op(&op) != 0);
@@ -324,13 +320,12 @@ EXPORT_SYMBOL(bind_evtchn_to_irq);
 
 void unbind_evtchn_from_irq(unsigned int irq)
 {
-       evtchn_op_t op;
+       evtchn_op_t op = { .cmd = EVTCHNOP_close };
        int evtchn = irq_to_evtchn[irq];
 
        spin_lock(&irq_mapping_update_lock);
 
        if ((--irq_bindcount[irq] == 0) && (evtchn != -1)) {
-               op.cmd          = EVTCHNOP_close;
                op.u.close.dom  = DOMID_SELF;
                op.u.close.port = evtchn;
                BUG_ON(HYPERVISOR_event_channel_op(&op) != 0);
@@ -378,7 +373,7 @@ static void do_nothing_function(void *ign)
 /* Rebind an evtchn so that it gets delivered to a specific cpu */
 static void rebind_irq_to_cpu(unsigned irq, unsigned tcpu)
 {
-       evtchn_op_t op;
+       evtchn_op_t op = { .cmd = EVTCHNOP_bind_vcpu };
        int evtchn;
 
        spin_lock(&irq_mapping_update_lock);
@@ -389,7 +384,6 @@ static void rebind_irq_to_cpu(unsigned irq, unsigned tcpu)
        }
 
        /* Send future instances of this interrupt to other vcpu. */
-       op.cmd = EVTCHNOP_bind_vcpu;
        op.u.bind_vcpu.port = evtchn;
        op.u.bind_vcpu.vcpu = tcpu;
 
@@ -518,10 +512,9 @@ static inline void pirq_query_unmask(int pirq)
 
 static unsigned int startup_pirq(unsigned int irq)
 {
-       evtchn_op_t op;
+       evtchn_op_t op = { .cmd = EVTCHNOP_bind_pirq };
        int evtchn;
 
-       op.cmd               = EVTCHNOP_bind_pirq;
        op.u.bind_pirq.pirq  = irq;
        /* NB. We are happy to share unless we are probing. */
        op.u.bind_pirq.flags = probing_irq(irq) ? 0 : BIND_PIRQ__WILL_SHARE;
@@ -547,7 +540,7 @@ static unsigned int startup_pirq(unsigned int irq)
 
 static void shutdown_pirq(unsigned int irq)
 {
-       evtchn_op_t op;
+       evtchn_op_t op = { .cmd = EVTCHNOP_close };
        int evtchn = irq_to_evtchn[irq];
 
        if (!VALID_EVTCHN(evtchn))
@@ -555,7 +548,6 @@ static void shutdown_pirq(unsigned int irq)
 
        mask_evtchn(evtchn);
 
-       op.cmd          = EVTCHNOP_close;
        op.u.close.dom  = DOMID_SELF;
        op.u.close.port = evtchn;
        BUG_ON(HYPERVISOR_event_channel_op(&op) != 0);
@@ -666,6 +658,7 @@ void irq_resume(void)
                        continue;
 
                /* Get a new binding from Xen. */
+               memset(&op, 0, sizeof(op));
                op.cmd              = EVTCHNOP_bind_virq;
                op.u.bind_virq.virq = virq;
                op.u.bind_virq.vcpu = 0;
@@ -689,6 +682,7 @@ void irq_resume(void)
                evtchn_to_irq[evtchn] = -1;
 
                /* Get a new binding from Xen. */
+               memset(&op, 0, sizeof(op));
                op.cmd = EVTCHNOP_bind_ipi;
                op.u.bind_ipi.vcpu = 0;
                BUG_ON(HYPERVISOR_event_channel_op(&op) != 0);
index 92e37850b3e6d64cda75abf72aecc2e477c58a48..5deb5b0cb6b35e940cca5f7d766e7b99f5509cbc 100644 (file)
@@ -68,8 +68,13 @@ static void unmap_frontend_page(blkif_t *blkif)
 int blkif_map(blkif_t *blkif, unsigned long shared_page, unsigned int evtchn)
 {
        blkif_sring_t *sring;
-       evtchn_op_t op = { .cmd = EVTCHNOP_bind_interdomain };
        int err;
+       evtchn_op_t op = {
+               .cmd = EVTCHNOP_bind_interdomain,
+               .u.bind_interdomain.dom1 = DOMID_SELF,
+               .u.bind_interdomain.dom2 = blkif->domid,
+               .u.bind_interdomain.port1 = 0,
+               .u.bind_interdomain.port2 = evtchn };
 
        if ( (blkif->blk_ring_area = alloc_vm_area(PAGE_SIZE)) == NULL )
                return -ENOMEM;
@@ -80,10 +85,6 @@ int blkif_map(blkif_t *blkif, unsigned long shared_page, unsigned int evtchn)
                return err;
        }
 
-       op.u.bind_interdomain.dom1 = DOMID_SELF;
-       op.u.bind_interdomain.dom2 = blkif->domid;
-       op.u.bind_interdomain.port1 = 0;
-       op.u.bind_interdomain.port2 = evtchn;
        err = HYPERVISOR_event_channel_op(&op);
        if (err) {
                unmap_frontend_page(blkif);
index 00caac5d95fe8f46f4b08eab4aff0bcb34a8f5a6..c30ab0f8b0955599312c1eeb582212575adf0370 100644 (file)
@@ -485,8 +485,11 @@ static void watch_for_status(struct xenbus_watch *watch, const char *node)
 static int setup_blkring(struct xenbus_device *dev, struct blkfront_info *info)
 {
        blkif_sring_t *sring;
-       evtchn_op_t op;
        int err;
+       evtchn_op_t op = {
+               .cmd = EVTCHNOP_alloc_unbound,
+               .u.alloc_unbound.dom = DOMID_SELF,
+               .u.alloc_unbound.remote_dom = info->backend_id };
 
        info->ring_ref = GRANT_INVALID_REF;
 
@@ -508,9 +511,6 @@ static int setup_blkring(struct xenbus_device *dev, struct blkfront_info *info)
        }
        info->ring_ref = err;
 
-       op.cmd = EVTCHNOP_alloc_unbound;
-       op.u.alloc_unbound.dom = DOMID_SELF;
-       op.u.alloc_unbound.remote_dom = info->backend_id;
        err = HYPERVISOR_event_channel_op(&op);
        if (err) {
                gnttab_end_foreign_access(info->ring_ref, 0);
index 85cf5d7362e4d2d0c0ac1f7dc2e6241d0aed99b2..364025d8f823e75a0dd7f2dc89610ea22dc5456a 100644 (file)
@@ -68,8 +68,13 @@ static void unmap_frontend_page(blkif_t *blkif)
 int blkif_map(blkif_t *blkif, unsigned long shared_page, unsigned int evtchn)
 {
        blkif_sring_t *sring;
-       evtchn_op_t op = { .cmd = EVTCHNOP_bind_interdomain };
        int err;
+       evtchn_op_t op = {
+               .cmd = EVTCHNOP_bind_interdomain,
+               .u.bind_interdomain.dom1 = DOMID_SELF,
+               .u.bind_interdomain.dom2 = blkif->domid,
+               .u.bind_interdomain.port1 = 0,
+               .u.bind_interdomain.port2 = evtchn };
 
        if ((blkif->blk_ring_area = alloc_vm_area(PAGE_SIZE)) == NULL)
                return -ENOMEM;
@@ -80,10 +85,6 @@ int blkif_map(blkif_t *blkif, unsigned long shared_page, unsigned int evtchn)
                return err;
        }
 
-       op.u.bind_interdomain.dom1 = DOMID_SELF;
-       op.u.bind_interdomain.dom2 = blkif->domid;
-       op.u.bind_interdomain.port1 = 0;
-       op.u.bind_interdomain.port2 = evtchn;
        err = HYPERVISOR_event_channel_op(&op);
        if (err) {
                unmap_frontend_page(blkif);
index b8b495ecb33cbca00c1ea86ef85b0fba1636298c..ab8f9518c7ef985581daf29cbf6d948408dfdfa4 100644 (file)
@@ -177,8 +177,13 @@ static void unmap_frontend_pages(netif_t *netif)
 int netif_map(netif_t *netif, unsigned long tx_ring_ref,
              unsigned long rx_ring_ref, unsigned int evtchn)
 {
-       evtchn_op_t op = { .cmd = EVTCHNOP_bind_interdomain };
        int err;
+       evtchn_op_t op = {
+               .cmd = EVTCHNOP_bind_interdomain,
+               .u.bind_interdomain.dom1 = DOMID_SELF,
+               .u.bind_interdomain.dom2 = netif->domid,
+               .u.bind_interdomain.port1 = 0,
+               .u.bind_interdomain.port2 = evtchn };
 
        netif->comms_area = alloc_vm_area(2*PAGE_SIZE);
        if (netif->comms_area == NULL)
@@ -190,10 +195,6 @@ int netif_map(netif_t *netif, unsigned long tx_ring_ref,
                return err;
        }
 
-       op.u.bind_interdomain.dom1 = DOMID_SELF;
-       op.u.bind_interdomain.dom2 = netif->domid;
-       op.u.bind_interdomain.port1 = 0;
-       op.u.bind_interdomain.port2 = evtchn;
        err = HYPERVISOR_event_channel_op(&op);
        if (err) {
                unmap_frontend_pages(netif);
index 7bd156625b4478c29f676f56923e8bf3f76b5a6b..f78cbad13e10e93f75d168002e7d98cc125ec3f5 100644 (file)
@@ -972,8 +972,11 @@ static void watch_for_status(struct xenbus_watch *watch, const char *node)
 
 static int setup_device(struct xenbus_device *dev, struct netfront_info *info)
 {
-       evtchn_op_t op;
        int err;
+       evtchn_op_t op = {
+               .cmd = EVTCHNOP_alloc_unbound,
+               .u.alloc_unbound.dom = DOMID_SELF,
+               .u.alloc_unbound.remote_dom = info->backend_id };
 
        info->tx_ring_ref = GRANT_INVALID_REF;
        info->rx_ring_ref = GRANT_INVALID_REF;
@@ -1010,9 +1013,6 @@ static int setup_device(struct xenbus_device *dev, struct netfront_info *info)
        }
        info->rx_ring_ref = err;
 
-       op.cmd = EVTCHNOP_alloc_unbound;
-       op.u.alloc_unbound.dom = DOMID_SELF;
-       op.u.alloc_unbound.remote_dom = info->backend_id;
        err = HYPERVISOR_event_channel_op(&op);
        if (err) {
                xenbus_dev_error(dev, err, "allocating event channel");
index 43c6f6e0cc46065b534e745421a21af8d5ccd59e..514cf1130a31d7f8be5765af6de2f6710932f1cc 100644 (file)
@@ -117,8 +117,13 @@ unmap_frontend_page(tpmif_t *tpmif)
 int
 tpmif_map(tpmif_t *tpmif, unsigned long shared_page, unsigned int evtchn)
 {
-       evtchn_op_t op = {.cmd = EVTCHNOP_bind_interdomain };
        int err;
+       evtchn_op_t op = {
+               .cmd = EVTCHNOP_bind_interdomain,
+               .u.bind_interdomain.dom1 = DOMID_SELF,
+               .u.bind_interdomain.dom2 = tpmif->domid,
+               .u.bind_interdomain.port1 = 0,
+               .u.bind_interdomain.port2 = evtchn };
 
        if ((tpmif->tx_area = alloc_vm_area(PAGE_SIZE)) == NULL)
                return -ENOMEM;
@@ -129,10 +134,6 @@ tpmif_map(tpmif_t *tpmif, unsigned long shared_page, unsigned int evtchn)
                return err;
        }
 
-       op.u.bind_interdomain.dom1 = DOMID_SELF;
-       op.u.bind_interdomain.dom2 = tpmif->domid;
-       op.u.bind_interdomain.port1 = 0;
-       op.u.bind_interdomain.port2 = evtchn;
        err = HYPERVISOR_event_channel_op(&op);
        if (err) {
                unmap_frontend_page(tpmif);
index 384f39ffcb6565f89592e5734c336b08acd3fc23..8fda9cee7265ee56226e1d5a6b5a828dd07fd195 100644 (file)
@@ -244,8 +244,11 @@ static int setup_tpmring(struct xenbus_device *dev,
 {
        tpmif_tx_interface_t *sring;
        struct tpm_private *tp = &my_private;
-       evtchn_op_t op;
        int err;
+       evtchn_op_t op = {
+               .cmd = EVTCHNOP_alloc_unbound,
+               .u.alloc_unbound.dom = DOMID_SELF,
+               .u.alloc_unbound.remote_dom = backend_id } ;
 
        sring = (void *)__get_free_page(GFP_KERNEL);
        if (!sring) {
@@ -268,9 +271,6 @@ static int setup_tpmring(struct xenbus_device *dev,
        }
        info->ring_ref = err;
 
-       op.cmd = EVTCHNOP_alloc_unbound;
-       op.u.alloc_unbound.dom = DOMID_SELF;
-       op.u.alloc_unbound.remote_dom = backend_id;
        err = HYPERVISOR_event_channel_op(&op);
        if (err) {
                gnttab_end_foreign_access(info->ring_ref, 0);
index d2f5279be89a772b1e220af07ed685c7fb4fa664..149f01fe7bc72d6e3fa9e15383002f14c18a3474 100644 (file)
@@ -123,9 +123,9 @@ static inline void clear_evtchn(int port)
 
 static inline void notify_remote_via_evtchn(int port)
 {
-       evtchn_op_t op;
-       op.cmd = EVTCHNOP_send;
-       op.u.send.local_port = port;
+       evtchn_op_t op = {
+               .cmd = EVTCHNOP_send,
+               .u.send.local_port = port };
        (void)HYPERVISOR_event_channel_op(&op);
 }
 
index 3bdacf36a34c59d33a3b9ca4d7829591b4955118..ed6256654b56ec83fc145e21bf81c052484ff69e 100644 (file)
@@ -37,13 +37,12 @@ int xc_evtchn_alloc_unbound(int xc_handle,
                             u32 dom,
                             int *port)
 {
-    evtchn_op_t op;
     int         rc;
-
-    op.cmd = EVTCHNOP_alloc_unbound;
-    op.u.alloc_unbound.remote_dom = (domid_t)remote_dom;
-    op.u.alloc_unbound.dom  = (domid_t)dom;
-    op.u.alloc_unbound.port = (port != NULL) ? *port : 0;
+    evtchn_op_t op = {
+        .cmd = EVTCHNOP_alloc_unbound,
+        .u.alloc_unbound.remote_dom = (domid_t)remote_dom,
+        .u.alloc_unbound.dom  = (domid_t)dom,
+        .u.alloc_unbound.port = (port != NULL) ? *port : 0 };
 
     if ( (rc = do_evtchn_op(xc_handle, &op)) == 0 )
     {
@@ -61,15 +60,13 @@ int xc_evtchn_bind_interdomain(int xc_handle,
                                int *port1,
                                int *port2)
 {
-    evtchn_op_t op;
     int         rc;
-
-    op.cmd = EVTCHNOP_bind_interdomain;
-    op.u.bind_interdomain.dom1  = (domid_t)dom1;
-    op.u.bind_interdomain.dom2  = (domid_t)dom2;
-    op.u.bind_interdomain.port1 = (port1 != NULL) ? *port1 : 0;
-    op.u.bind_interdomain.port2 = (port2 != NULL) ? *port2 : 0;
-
+    evtchn_op_t op = {
+        .cmd = EVTCHNOP_bind_interdomain,
+        .u.bind_interdomain.dom1  = (domid_t)dom1,
+        .u.bind_interdomain.dom2  = (domid_t)dom2,
+        .u.bind_interdomain.port1 = (port1 != NULL) ? *port1 : 0,
+        .u.bind_interdomain.port2 = (port2 != NULL) ? *port2 : 0 };
 
     if ( (rc = do_evtchn_op(xc_handle, &op)) == 0 )
     {
@@ -87,12 +84,11 @@ int xc_evtchn_bind_virq(int xc_handle,
                         int virq,
                         int *port)
 {
-    evtchn_op_t op;
     int         rc;
-
-    op.cmd = EVTCHNOP_bind_virq;
-    op.u.bind_virq.virq = (u32)virq;
-    op.u.bind_virq.vcpu = 0;
+    evtchn_op_t op = {
+        .cmd = EVTCHNOP_bind_virq,
+        .u.bind_virq.virq = (u32)virq,
+        .u.bind_virq.vcpu = 0 };
 
     if ( (rc = do_evtchn_op(xc_handle, &op)) == 0 )
     {
@@ -108,10 +104,10 @@ int xc_evtchn_close(int xc_handle,
                     u32 dom,
                     int port)
 {
-    evtchn_op_t op;
-    op.cmd = EVTCHNOP_close;
-    op.u.close.dom  = (domid_t)dom;
-    op.u.close.port = port;
+    evtchn_op_t op = {
+        .cmd          = EVTCHNOP_close,
+        .u.close.dom  = (domid_t)dom,
+        .u.close.port = port };
     return do_evtchn_op(xc_handle, &op);
 }
 
@@ -119,9 +115,9 @@ int xc_evtchn_close(int xc_handle,
 int xc_evtchn_send(int xc_handle,
                    int local_port)
 {
-    evtchn_op_t op;
-    op.cmd = EVTCHNOP_send;
-    op.u.send.local_port = local_port;
+    evtchn_op_t op = {
+        .cmd = EVTCHNOP_send,
+        .u.send.local_port = local_port };
     return do_evtchn_op(xc_handle, &op);
 }
 
@@ -131,13 +127,12 @@ int xc_evtchn_status(int xc_handle,
                      int port,
                      xc_evtchn_status_t *status)
 {
-    evtchn_op_t op;
     int         rc;
+    evtchn_op_t op = {
+        .cmd           = EVTCHNOP_status,
+        .u.status.dom  = (domid_t)dom,
+        .u.status.port = port };
 
-    op.cmd = EVTCHNOP_status;
-    op.u.status.dom  = (domid_t)dom;
-    op.u.status.port = port;
-   
     if ( (rc = do_evtchn_op(xc_handle, &op)) == 0 )
         memcpy(status, &op.u.status, sizeof(*status));